package com.czy.owner.ui.workorder.orderviewholder;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.MyOrderModel;
import com.czy.owner.entity.WorkOrderModel;
import com.czy.owner.global.Constants;
import com.czy.owner.ui.store.OnLineOrderActivity2;
import com.czy.owner.ui.workorder.OrderFragment;
import com.czy.owner.ui.workorder.PaidSubscriptionActivity;
import com.czy.owner.utils.DecimalUtil;
import com.czy.owner.utils.PhoneUtils;
import com.czy.owner.utils.SharedPreferencesUtils;
import com.czy.owner.utils.StringUtils;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.widget.CountdownView;
import com.easyrecycleview.adapter.BaseViewHolder;

/**
 * Created by hedepu on 2017-08-28
 */

public class OrderPendingPaymentViewHolder extends BaseViewHolder<WorkOrderModel> {
    private TextView tv_order_number, tv_order_state, tv_order_item, tv_order_service_time, tv_order_jishi, tv_order_dingjing, tv_store_name;
    private CountdownView cv_seckill;
    private TextView btn_order_paid;
    private Context context;

    public OrderPendingPaymentViewHolder(ViewGroup parent, Context ctx) {
        super(parent, R.layout.item_order_pending_payment);
        tv_order_number = $(R.id.tv_order_number);
        tv_order_item = $(R.id.tv_order_item);
        tv_order_service_time = $(R.id.tv_order_service_time);
        tv_order_state = $(R.id.tv_order_state);
        tv_order_jishi = $(R.id.tv_order_jishi);
        tv_order_dingjing = $(R.id.tv_order_dingjing);
        cv_seckill = $(R.id.cv_seckill);
        btn_order_paid = $(R.id.btn_order_paid);
        tv_store_name = $(R.id.tv_store_name);

        this.context = ctx;
    }

    @Override
    public void setData(final WorkOrderModel model) {
        super.setData(model);
        tv_store_name.setText(model.getStoreName());
        tv_order_number.setText("工单编号: " + model.getOrderNumber());
//        tv_order_service_time.setText(TimeUtils.timeStamp2Date(model.getServiceTime(), "yyyy-MM-dd HH:mm"));
//        String daytime = TimeUtils.timeStamp2Date(model.getServiceTime(), "HH");
//        String huor;
//        if (Integer.parseInt(daytime) > 12) {
//            huor = "上午";
//        } else {
//            huor = "下午";
//        }
//        tv_order_service_time.setText(TimeUtils.timeStamp2Date(model.getServiceTime(), "yyyy-MM-dd") + " " + TimeUtils.getWeeky(Long.parseLong(model.getServiceTime()))
//                + huor);
        tv_order_service_time.setText(model.getConvertServiceTime());
        tv_order_item.setText(StringUtils.getString(model.getOrderItemNameStr(), "无"));
        tv_order_jishi.setText(model.getLicenseNumber() + "  " + model.getChName());
//        tv_order_dingjing.setText("¥" + DecimalUtil.formatNum(model.getActualDepositAmount() + ""));
        tv_order_dingjing.setText("¥" + DecimalUtil.formatNum(model.getTotalPrice()));

        cv_seckill.start(Long.parseLong(model.getCreateTime()) + Integer.parseInt(OrderFragment.unPaidDepositTime) * 60 * 60 * 1000 - PhoneUtils.getTime());
        btn_order_paid.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent ti = new Intent(getContext(), PaidSubscriptionActivity.class);
                ti.putExtra("orderNumber", model.getOrderNumber());
                ti.putExtra("userOrderId", model.getUserOrderId());
                ti.putExtra("type", "2");
                ti.putExtra("storeId", model.getStoreId());
                getContext().startActivity(ti);
            }
        });
    }
}
